<?php


namespace app\index\controller;


use app\BaseController;
use app\common\lib\sms\TencentSms;
use app\index\business\smsBus;
use app\index\validate\memberInfo;
use think\exception\ValidateException;

class Sms extends BaseController
{
    public function sendCode(){
        $phone = $this->request->param('phone');
        $data = [
            'phone' => $phone
        ];
        try {
            validate(memberInfo::class)->scene('member_send_code')->check($data);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getError());
        }
        if(smsBus::sendCode($phone)){
            return show(config('status.success'),'短信发送成功');
        }
        return show(config('status.success'),'短信发送失败');
    }
    public function sendCodePassword(){
        $phone = $this->request->param('phone');
        $data = [
            'phone_set' => $phone
        ];
        try {
            validate(memberInfo::class)->scene('member_change_password')->check($data);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getError());
        }
        if(smsBus::sendCodePassword($phone)){
            return show(config('status.success'),'短信发送成功');
        }
        return show(config('status.success'),'短信发送失败');
    }

    public function tencentSendCode(){
        $phone = $this->request->param('phone');
        $data = [
            'phone_set' => $phone
        ];
        try {
            validate(memberInfo::class)->scene('member_change_password')->check($data);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getError());
        }
        if(smsBus::tencentSendCodeBus($phone)){
            return show(config('status.success'),'短信发送成功');
        }
        return show(config('status.error'),'短信发送失败');

    }
}